package com.esms.esmsadmin.service;

import com.esms.esmsadmin.entity.RespPageBean;
import com.esms.esmsadmin.entity.StudentEntity;
import com.esms.esmsadmin.mapper.StudentMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StudentService {
    @Autowired
    StudentMapper studentMapper;
    public RespPageBean getStudentsByPage(Integer page, Integer size,String keywords) {
        if(page !=null && size!=null){
            page = (page - 1)*size;
        }
        List<StudentEntity> data = studentMapper.getStudentsByPage(page,size,keywords);
        Long total = studentMapper.getTotal(keywords);
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(data);
        respPageBean.setTotal(total);
        return respPageBean;
    }

    public Integer addStudent(StudentEntity student) {
        return studentMapper.insertSelective(student);
    }

    public int updateStu(StudentEntity student) {
        return studentMapper.updateByPrimaryKeySelective(student);
    }

    public int deleteStuByEid(Integer id) {
        return studentMapper.deleteByPrimaryKey(id);
    }
}
